<?php

	class LoginView {
	  
	  	private $m_username = 'username';
		private $m_password = 'password';
		private $m_loginButton = 'loginButton';
		private $m_logoutButton = 'logoutButton';
		private $m_checkButton = 'checkButton';
		
		
		  //Funktion som returnerar HTML för ett inloggningsformulär
		  public function DoLoginBox() {
		    return 
		    '<form method="get">
			    <fieldset>
					Name: <input type="text" name="'.$this->m_username.'" /><br />
					Password: <input type="text" name="'.$this->m_password.'" /><br />
					<input type="submit" value="Login" name="'.$this->m_loginButton.'"/>
					Remember me<input type="checkbox" value="Remember me" name="'.$this->m_checkButton.'"/>
				</fieldset>
			</form>';
		  }
		  
		  public function DoLogoutBox() {
		  	return 
		  	'<form method="get">
		  		<input type="submit" value="Logout" name="'.$this->m_logoutButton.'" />
		  	</form>';
		  }
		  
		  //Returnerar användarnamnet
		  public function GetUserName() {
		  	if (isset($_GET[$this->m_username])) {
		  		return $_GET[$this->m_username] ;
		  		
			}
			else {
				return null;
			}
		  }
		  
		  //Returnerar lösenordet
		  public function GetPassword() {
		  	if (isset($_GET[$this->m_password])) {
		  		return $_GET[$this->m_password];
		  		
			}
			else {
				return null;
			}
		  }
		  
		  //Är remember me boxen iklickad returneras true, annars false
		  public function RememberMe(){
		  	if(isset($_GET[$this->m_checkButton])) {
		  		return true;
		  	}
			else{
				return false;
			}
		  	
		  }
		  
		  //Har användaren klickat på login
		  public function TriedToLogin() {
		  	if (isset($_GET[$this->m_loginButton])) {
		  		return true;
		  		
			}
			else {
				return false;
			}
		  }
		  
		  //Har användaren klickat på logout
		  public function TriedToLogout() {
		  	
		  	if (isset($_GET[$this->m_logoutButton])) {
		  		return true;
		  		
			}
			else {
				return false;
			}
		  }
		  
		  //Sätter en coookie
		  public function SetCookie($username, $password) {
		  	
                setcookie("username", $username, time()+3600);
				setcookie("password", $password, time()+3600);
   
		  }
		  
		  //Förstör cookie
		  public function UnsetCookie(){
		  	
		  	setcookie("username", "", time()-3600);
			setcookie("password", "", time()-3600);
		  }
        
		  
	}
